package com.xiaoxing.zhinenghuacangku_linyi.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.dds.soap.SoapUtil;
import com.jess.arms.base.ArmsBaseConstants;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.SharedPreferencesHelper;
import com.xiaoxing.gifloadingview.LoadingDialogUtil;
import com.xiaoxing.zhinenghuacangku_linyi.R;
import com.xiaoxing.zhinenghuacangku_linyi.R2;
import com.xiaoxing.zhinenghuacangku_linyi.di.component.DaggerLinYi_MenuSelectionComponent;
import com.xiaoxing.zhinenghuacangku_linyi.di.module.LinYi_MenuSelectionModule;
import com.xiaoxing.zhinenghuacangku_linyi.mvp.contract.LinYi_MenuSelectionContract;
import com.xiaoxing.zhinenghuacangku_linyi.mvp.presenter.LinYi_MenuSelectionPresenter;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import butterknife.BindView;
import butterknife.OnClick;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.Utils;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_MENU_SELECTION_ACTIVITY)
public class LinYi_MenuSelectionActivity extends BaseActivity
        <LinYi_MenuSelectionPresenter> implements LinYi_MenuSelectionContract.View {


    protected SharedPreferencesHelper mSharedPreferencesHelper;
    @BindView(R2.id.btn_ru_ku)
    Button btnRuKu;
    @BindView(R2.id.btn_zhi_jian_ru_ku)
    Button btnZhiJianRuKu;
    @BindView(R2.id.btn_chu_ku)
    Button btnChuKu;
    @BindView(R2.id.btn_tui_ku)
    Button btnTuiKu;
    @BindView(R2.id.btn_yan_shi_chu_ku)
    Button btnYanShiChuKu;
    @BindView(R2.id.btn_kai_guan_men)
    Button btnKaiGuanMen;
    Button btn_zhijianruku;
    String url = "";
    private Button btn_li_ku;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLinYi_MenuSelectionComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .linYi_MenuSelectionModule(new LinYi_MenuSelectionModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {

        return R.layout.zhi_neng_cang_ku_lin_yi_activity_menu_selection_lin_yi; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0

    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
//        String httpUrl = mSharedPreferencesHelper.getString(HTTP_URL);
//        RetrofitUrlManager.getInstance().setGlobalDomain(httpUrl);
        btn_li_ku = findViewById(R.id.btn_li_ku);
        btn_zhijianruku = findViewById(R.id.btn_zhijianruku);
        mSharedPreferencesHelper = SharedPreferencesHelper.getInstance(this);
        url = "http://" + mSharedPreferencesHelper.getString(ArmsBaseConstants.IP) + ":"
                + mSharedPreferencesHelper.getString(ArmsBaseConstants.PORT)
                + "/StoreService.asmx";
        btn_li_ku.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String methodName = "CheckLiKuBufferStatus";
                SoapParams params = new SoapParams();
                params.put("buffername", "D01");
                params.put("status", "1");
                SoapUtil.getInstance(LinYi_MenuSelectionActivity.this).callEntry(url, BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
                    @Override
                    public void onSuccess(int statusCode, SoapObject object) {
                        LoadingDialogUtil.dismissDialog();

                        String result = object.getProperty(methodName + "Result").toString();

                        if (result.equals("true")) {
                            startActivity(new Intent(LinYi_MenuSelectionActivity.this, LinYi_LiKuRuKuActivity.class));
                        } else {
                            Toast.makeText(LinYi_MenuSelectionActivity.this, "巷道口占用中", Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, String content, Throwable error) {

                    }

                    @Override
                    public void onFailure(int statusCode, SoapFault fault) {

                    }
                }, mSharedPreferencesHelper.getString(BaseConstants.API_USER_NAME), mSharedPreferencesHelper.getString(BaseConstants.API_PWD));

//                Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_LI_KU_RU_KU);
            }
        });
        btn_zhijianruku.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LinYi_MenuSelectionActivity.this, ZhijianfinishActivity.class));
            }
        });
//        ToolbarUtils.initToolbarTitleBack(this, "default_title");
//        if (isLinYi) {
////            btnYanShiChuKu.setVisibility(View.VISIBLE);
//            btnKaiGuanMen.setVisibility(View.VISIBLE);
//            btnZhiJianRuKu.setVisibility(View.VISIBLE);
//        } else {
//
//        }


    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @OnClick(R2.id.btn_chou_jian_chu_ku)
    public void chouJianChuKu() {
        Utils.navigation(this, RouterHub.ZHI_NENG_HUA_CANG_KU_ZHI_JIAN_ACTIVITY_CHOU_JIAN_CHU_KU_LIE_BIAO);
    }

    @OnClick(R2.id.btn_ru_ku)
    public void onBtnRuKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_STORAGE_ACTIVITY);
    }

    @OnClick(R2.id.btn_zhi_jian_ru_ku)
    public void onBtnZhiJianRuKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_ZHI_JIAN_RU_KU);
    }

    @OnClick(R2.id.btn_chu_ku)
    public void onBtnChuKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_OUT_OF_THE_LIBRARY_ACTIVITY);
    }

    @OnClick(R2.id.btn_tui_ku)
    public void onBtnTuiKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_RETURN_LIBRARY_MENU_ACTIVITY);
    }

    @OnClick(R2.id.btn_yi_ku)
    public void onBtnYiKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_YI_KU);
    }

    @OnClick(R2.id.btn_ru_ku_qing_zhang)
    public void onBtnRuKuQingZhangClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_RU_KU_QING_ZHANG);
    }

    @OnClick(R2.id.btn_huan_chong_wei_zhi_kong)
    public void onBtnHuanChongWeiZhiZhiKongClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_ZHI_KONG_HUAN_CHONG_WEI);
    }

    @OnClick(R2.id.btn_yi_ku_qing_zhang)
    public void onBtnYiKuQingZhangClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_YI_KU_QING_ZHANG);
    }

    @OnClick(R2.id.btn_yan_shi_chu_ku)
    public void onBtnYanShiChuKuClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_LI_YI_CHU_KU);
    }


    @OnClick(R2.id.btn_kai_guan_men)
    public void onBtnKaiGuanMenViewClicked() {
        Utils.navigation(LinYi_MenuSelectionActivity.this, RouterHub.ZHI_NENG_HUA_CANG_KU_LIN_YI_ACTIVITY_LIN_YI_KAI_GUAN_MEN);
    }

    @OnClick(R2.id.btn_chou_jian_tui_ku)
    public void btnChouJianTuiKu() {
        Utils.navigation(this, RouterHub.ZHI_NENG_HUA_CANG_KU_ZHI_JIAN_ACTIVITY_CHOU_JIAN_TUI_KU_LIE_BIAO);
    }

}
